﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Business;
using Ecreate.Model;
using System.Text.RegularExpressions;
using Ecreate.Popedom.Service.SpringImpl;

namespace Ecreate.Web.pages
{
    public partial class orderlist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            gv.Visible = true;
            BindData();
        }

        private void BindData()
        {
            string sql = "select OrderID,KickOrderID,SN,Times,SellAddress,SellPhoneNumber,ProductName,Price,CustName,CustPhoneNumber,CustAddress,PayAccount,PayDate,IsCheckName from v_order where IsCheck='1'";
            if (txtPhoneNumber.Text.Length > 0)
            {
                sql += " and (SellPhoneNumber='" + txtPhoneNumber.Text + "' or CustPhoneNumber='" + txtPhoneNumber.Text + "')";
            }
            System.Data.DataTable dt = usercontrol.GG.GetTable(sql);
            gv.DataSource = dt;
            gv.DataBind();
        }

        protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                foreach (TableCell cell in e.Row.Cells)
                {
                    string text = cell.Text;
                    cell.Text = GetHeaderText(text);
                }
            }
        }

        private string GetHeaderText(string text)
        {
            string headertext = text;
            string[] fields = "OrderID,KickOrderID,SN,Times,SellAddress,SellPhoneNumber,ProductName,Price,CustName,CustPhoneNumber,CustAddress,PayAccount,PayDate,IsCheckName".Split(new char[] { ',' });
            string[] titles = "订单编号,被此订单顶掉,当前排序,被顶掉次数,销售地址,销售电话,产品名称,价格,消费者姓名,消费者电话,消费者收件地址,付款账号,付款日期,付款确认".Split(new char[] { ',' });
            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i] == text)
                {
                    headertext = titles[i];
                    break;
                }
            }
            return headertext;
        }

        protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gv.PageIndex = e.NewPageIndex;
            BindData();
        }
    }
}
